import { defineComponent, h } from 'vue'
export default defineComponent({
  name: 'DModal',
  props: {
    title: { default: null },
    visible: { type: Boolean, default: false },
    confirmLoading: { type: Boolean, default: false },
    push: { type: Boolean, defaule: false }
  },
  emits: ['ok', 'cancel'],
  setup(props, context) {
    const handleOk = () => {
      context.emit('ok')
    }

    const handleCancel = () => {
      context.emit('cancel')
    }

    return {
      handleOk,
      handleCancel
    }
  },
  render() {
    const { view, title, visible, confirmLoading, handleOk, handleCancel, push } = this
    const slots = this.$slots
    const { footer } = slots
    return (
      <a-drawer
        title={title}
        visible={visible}
        push={push}
        footer={
          footer ? (
            h(footer)
          ) : (
            <a-space>
              <a-button onClick={handleCancel}>
                取消
              </a-button>
              <a-button type="primary" loading={confirmLoading} onClick={handleOk}>
                确认
              </a-button>
            </a-space>
          )
        }
        onClose={handleCancel}>
        {slots}
      </a-drawer>
    )
  }
})
